package com.xiaoluo.a17_countdown;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;


/**
 * @ Created on: 2020/1/13
 * @Author: LEGION XiaoLuo
 * @ Description:
 */
public class CountDownDialog extends Dialog {
    private Window mWindow;
    private CountDownView mCountDownView;

    public CountDownDialog(Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(getLayoutId(context));
        init();
    }

    private void init() {
        mWindow = getWindow();
        WindowManager.LayoutParams wl = mWindow.getAttributes();
      //  wl.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        wl.width = UiUtil.div(1920);
        wl.height = UiUtil.div(1080);
        wl.dimAmount = 0.6f;
        mWindow.setGravity(Gravity.TOP | Gravity.START);
        mWindow.getDecorView().setPadding(0, 0, 0, 0);
        mWindow.setBackgroundDrawableResource(android.R.color.transparent);
        mWindow.setAttributes(wl);
    }

    private View getLayoutId(Context context) {
        mCountDownView = new CountDownView(context);
        return mCountDownView;
    }

    public void start(long time, long interval) {
        mCountDownView.start(time, interval);
    }

    public void cancelCountDown() {
        mCountDownView.cancel();
    }
}
